/**
 * @author: Niimp
 * @date: 2023/5/5 14:17
 * @statement:
 */
package com.dz.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dz.config.result.ResponseResult;
import com.dz.pojoDto.City;
import com.dz.pojoDto.QueryDataRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;

@Api(tags = "风险管理一张图")
@RestController
@RequestMapping("/riskManagementImage")
public class RiskManagementController {

    @Resource
    private RestTemplate restTemplate;

    private final String PAYMENTURL = "http://localhost:8002/riskManagementImage/";

    @ApiOperation(value = "行政区划查询")
    @PostMapping({"/queryAllXzqh"})
    @ResponseBody
    public ResponseResult queryAllXzqh(HttpServletRequest request) {
        return restTemplate.postForObject(PAYMENTURL + "queryAllXzqh", request,ResponseResult.class);
    }


    /**
     * @Description:查询 行政单元-灾害点详情
     */
    @ApiOperation(value = "地图数据")
    @PostMapping(value = "queryZhcxZhd", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseResult queryZhcxZhd(@RequestBody City city, HttpSession session) {
        return restTemplate.postForObject(PAYMENTURL + "queryZhcxZhd", city,ResponseResult.class);
    }

    @ApiOperation(value = "隐患点查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zhaa11a030", value = "市编码", required = true,defaultValue = "431200",  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zhaa11a032", value = "县编码", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zhaa11a024", value = "灾害类型01:滑坡 02:崩塌 03:泥石流 04:地面塌陷 06:地裂缝 07:地面沉降 00:不稳定斜坡",
                    required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zhaa11a012", value = "统一编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zhaa01c020", value = "隐患点年份", required = true,defaultValue = "2023", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zhaa11a022", value = "灾害名称关键字", required = false, dataType = "String", paramType = "query"),
    })
    @PostMapping("getHiddenDangerPoint")
    @ResponseBody
    public ResponseResult getHiddenDangerPoint(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "getHiddenDangerPoint", jsonObject,ResponseResult.class);
    }

    /**
     * @Description:查询 首页灾情统计
     */
    @ApiOperation(value = "首页灾情统计")
    @PostMapping("queryZhdBysy")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "市编码",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "county", value = "县编码", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "home", value = "乡编码", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "years", value = "年份",defaultValue = "2023", required = true,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "cxtypes", value = "查询类型(gmdj/xqdj/zqdj)",defaultValue = "gmdj", required = true,  dataType = "String", paramType = "query")
    })
    public ResponseResult queryZhdBysy(@RequestBody City city) {
        return restTemplate.postForObject(PAYMENTURL + "queryZhdBysy", city,ResponseResult.class);
    }


//    @ApiOperation(value = "市各地区隐患点统计")
//    @PostMapping("queryKeypointTj")
//    @ResponseBody
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "city", value = "市编码",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "county", value = "县编码",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "years", value = "年份",defaultValue = "2023", required = true,  dataType = "String", paramType = "query")
//
//    })
//    public ResponseResult queryKeypointTj(@RequestBody QueryKeypoint request){
//        String city = request.getCity();
//        String years = request.getYear();
//        try {
//            String url = DbConfig.Uri + "ZHCXNew/queryKeypointTj?";
//            Map<String,Object> parmaters = new HashMap<>();
//            parmaters.put("city",city);
//            parmaters.put("years",years);
//            String res = UrlHttpRequest.httpPost(url,parmaters);
//            JSONObject obj = JSONObject.parseObject(res);
//            if (obj.getBoolean("status")){
//                JSONArray arr = obj.getJSONArray("data");
//                List<Object> list = JSONArray.parseArray(arr.toString(),Object.class);
////                return new ResultObj("查询成功", list, true);
//                return new ResponseResult(200,true,"查询成功",list);
//            }{
////                return new ResultObj("查询失败", null, false);
//                return new ResponseResult(null,false,"查询失败",null);
//            }
//        }catch (Exception e){
//            e.printStackTrace();
////            return new ResultObj("查询异常", null, false);
//            return new ResponseResult(null,false,"查询异常",null);
//        }
//    }






    /**
     * 规模、险情、灾情
     * @param request
     * @return
     */

    @ApiOperation(value = "规模等级/险情等级/灾情等级")
    @PostMapping("queryDataDcd")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "市编码",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "county", value = "县编码", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "home", value = "乡编码", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "years", value = "年份",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "cxtypes", value = "查询类型(gmdj/xqdj/zqdj)",defaultValue = "gmdj", required = true,  dataType = "String", paramType = "query")
    })
//    public ResponseResult queryDataDcd(HttpServletRequest request){
    public ResponseResult queryDataDcd(@RequestBody QueryDataRequest request){
        return restTemplate.postForObject(PAYMENTURL + "queryDataDcd", request,ResponseResult.class);
    }


    @ApiOperation(value = "风险区信息查询")
    @PostMapping("queryRiskZoneInfo")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "市编码",defaultValue = "431200", required = true,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "county", value = "县编码", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "riskLevel", value = "风险等级(极高、高、中、低)", required = false,  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "风险区名称关键字", required = false,  dataType = "String", paramType = "query")
    })
    public ResponseResult queryRiskZoneInfo(@RequestBody JSONObject jsonObject){
        return restTemplate.postForObject(PAYMENTURL + "queryRiskZoneInfo", jsonObject,ResponseResult.class);
    }


}


